package my;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class QQFrame {

	public static void main(String[] args) {
		JFrame frame = new JFrame("QQ");
		frame.setBounds(500, 300, 400, 350);

		JPanel mainPanel = new JPanel();
		//mainPanel.setBorder(new LineBorder(Color.BLACK,5));
		frame.setContentPane(mainPanel);

		JPanel accountPanel = new JPanel();
		accountPanel.setBounds(100, 60, 200, 50);
		JLabel label = new JLabel("帐号：");
		accountPanel.add(label);
		JTextField tf = new JTextField();
		tf.setColumns(10);
		accountPanel.add(tf);
		//accountPanel.setBorder(new LineBorder(Color.RED));
		mainPanel.add(accountPanel);

		JPanel passwordPanel = new JPanel();
		passwordPanel.setBounds(100, 110, 200, 50);
		JLabel label1 = new JLabel("密码：");
		passwordPanel.add(label1);
		JPasswordField pwd = new JPasswordField();
		pwd.setColumns(10);
		passwordPanel.add(pwd);
		//passwordPanel.setBorder(new LineBorder(Color.RED));
		mainPanel.add(passwordPanel);

		JPanel btnPanel = new JPanel();
		btnPanel.setBounds(100, 160, 200, 50);
		JButton bt1 = new JButton("登录");
		JButton bt2 = new JButton("注册");
		bt2.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				QQRegisterFrame.start();
				frame.setVisible(false);
			}
		});
		btnPanel.add(bt1);
		btnPanel.add(bt2);
		//btnPanel.setBorder(new LineBorder(Color.RED));
		mainPanel.add(btnPanel);

		JPanel msgPanel = new JPanel();
		JLabel msgLabel = new JLabel();
		msgLabel.setBounds(0, 0, 295, 30);
		msgPanel.add(msgLabel);
		msgPanel.setBounds(100,210,300,50);
		//msgPanel.setBorder(new LineBorder(Color.red,5));
		msgPanel.setLayout(null);
		mainPanel.add(msgPanel);

		bt1.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				String user = tf.getText();//获取帐号输入框里面的值
				String password = pwd.getText();
				QQResponse response = QQClient.login(user,password);
				if(response.getSuccess()){
					//msgLabel.setText(response.getMsg());
					QQMainFrame.start(user,response.getFriends());
					frame.setVisible(false);//隐藏登录主界面
				}else{
					msgLabel.setText(response.getMsg());
				}
			}
		});

		frame.setLayout(null);//不使用系统布局方式
		//frame.setLayout(new FlowLayout());//流式布局
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//关闭窗体退出程序
		frame.setVisible(true);
	}

}
